import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/util/DbUtil.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

void main() async {
  test("insert sql", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");

    var row = {
      "name": "test2",
      'currentUserId': 'test00100',
      "value": "2023-05-13",
      "createTime": "",
      "updateTime": ""
    };
    int n = await database.insert("im_setting", row);
    print("insql n $n");
    assert(n > 0, "插入失败");
  });

  test("select sql", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");

    var row = {
      "name": "test2",
      "value": "2023-05-13",
      "createTime": "",
      "updateTime": ""
    };
    List list = await database.rawQuery("select * from im_setting");
    print("select data ${list.length}");
    print("select data ${jsonEncode(list)}");
    assert(list.length > 3, "插入失败");
  });
}
